//
//  NavgaitonController.swift
//  Weibo-Swift
//
//  Created by LYFDevelopment on 2017/4/11.
//  Copyright © 2017年 LYFDevelopment. All rights reserved.
//

import UIKit

class NavgaitonController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //影藏默认的navBar
        navigationBar.isHidden = true
    }
    //重写push方法，所有的push动作都调用该方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //如果不是栈底控制器才需要隐藏
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        if let vc = viewController as? BaseViewController {
            var title = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? "返回"
            }
            
            vc.navItem.leftBarButtonItem = UIBarButtonItem.init(title: title, target: self, action: #selector(popToBack))
        }
        super.pushViewController(viewController, animated: animated)

    }
    
    @objc private func popToBack(){
        
    }
}
